<?php

defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
if($_RQ['op']=='getteams'){
	$goodsid=intval($_RQ['goodsid']);
	$goods=pdo_get('jy_weishop_goods',array('id'=>$goodsid,'uniacid'=>$_SESSION['uniacid']));
	$goods=$this->model('model')->up_price($goods,$return['pluginset'],true);
	$groupnum=$goods['teamnum']?:2;
	$pindex = max(1, intval($_RQ['page']));
	$psize =6;
	$return['params']=$params=array();
	$params=array('uniacid'=>$_SESSION['uniacid'],'goodsid'=>$goodsid,'status'=>0);
	$status=intval($_RQ['status']);
	$num=intval($_RQ['num']);
	if($_RQ['keyword']){
		$params['title like']='%'.$_RQ['keyword'].'%';
		$return['params']['keyword']=$_RQ['keyword'];
	}
	if($num){
		$psize = $num;
	}
	$times=array();
	$goods['grouptime']=$goods['grouptime']?:48;
	$list=pdo_getslice('jy_weishop_groups_team',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach ($list as &$team) {
			//查询对应拼团还需人数
			$num1 = pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'plugin_name'=>'jy_newganfee','teamid'=>$team['id'],'status'=>10));
			$team['num'] = $groupnum - $num1;
			//查询团长信息
			$team['header']=cfc('core')->member_show($team['mid']);
			//查询团长地址
			$team['address']=model('core/member')->get_address_str($team['addressid']);
			$times[$team['id']]=model('jy_weishop/model')->date($team['createtime']+$goods['grouptime']*60-TIMESTAMP);
		}
	}
	$return['times']=$times;
	$return['list']=$list;
	exi($return);
}
